home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-04d.zip / 04d / CHIP / Porady / Niewidoczny w sieci / TOR 0.1.2.7 / vidalia-bundle-0.1.2.7-alpha-0.0.10.exe / Tor / Documents / control-spec.txt < prev    next >
Text File  |  2007-02-07  |  54KB  |  1,315 lines

  1. $Id: control-spec.txt 9484 2007-02-05 19:15:13Z nickm $
  2.  
  3.                    TC: A Tor control protocol (Version 1)
  4.  
  5. 0. Scope
  6.  
  7.   This document describes an implementation-specific protocol that is used
  8.   for other programs (such as frontend user-interfaces) to communicate with a
  9.   locally running Tor process.  It is not part of the Tor onion routing
  10.   protocol.
  11.  
  12.   This protocol replaces version 0 of TC, which is now deprecated.  For
  13.   reference, TC is described in "control-spec-v0.txt".  Implementors are
  14.   recommended to avoid using TC directly, but instead to use a library that
  15.   can easily be updated to use the newer protocol.  (Version 0 is used by Tor
  16.   versions 0.1.0.x; the protocol in this document only works with Tor
  17.   versions in the 0.1.1.x series and later.)
  18.  
  19. 1. Protocol outline
  20.  
  21.   TC is a bidirectional message-based protocol.  It assumes an underlying
  22.   stream for communication between a controlling process (the "client"
  23.   or "controller") and a Tor process (or "server").  The stream may be
  24.   implemented via TCP, TLS-over-TCP, a Unix-domain socket, or so on,
  25.   but it must provide reliable in-order delivery.  For security, the
  26.   stream should not be accessible by untrusted parties.
  27.  
  28.   In TC, the client and server send typed messages to each other over the
  29.   underlying stream.  The client sends "commands" and the server sends
  30.   "replies".
  31.  
  32.   By default, all messages from the server are in response to messages from
  33.   the client.  Some client requests, however, will cause the server to send
  34.   messages to the client indefinitely far into the future.  Such
  35.   "asynchronous" replies are marked as such.
  36.  
  37.   Servers respond to messages in the order messages are received.
  38.  
  39. 2. Message format
  40.  
  41. 2.1. Description format
  42.  
  43.   The message formats listed below use ABNF as described in RFC 2234.
  44.   The protocol itself is loosely based on SMTP (see RFC 2821).
  45.  
  46.   We use the following nonterminals from RFC 2822: atom, qcontent
  47.  
  48.   We define the following general-use nonterminals:
  49.  
  50.      String = DQUOTE *qcontent DQUOTE
  51.  
  52.   There are explicitly no limits on line length.  All 8-bit characters are
  53.   permitted unless explicitly disallowed.
  54.  
  55. 2.2. Commands from controller to Tor
  56.  
  57.     Command = Keyword Arguments CRLF / "+" Keyword Arguments CRLF Data
  58.     Keyword = 1*ALPHA
  59.     Arguments = *(SP / VCHAR)
  60.  
  61.   Specific commands and their arguments are described below in section 3.
  62.  
  63. 2.3. Replies from Tor to the controller
  64.  
  65.     Reply = *(MidReplyLine / DataReplyLine) EndReplyLine
  66.  
  67.     MidReplyLine = "-" ReplyLine
  68.     DataReplyLine = "+" ReplyLine Data
  69.     EndReplyLine = SP ReplyLine
  70.     ReplyLine = StatusCode [ SP ReplyText ]  CRLF
  71.     ReplyText = XXXX
  72.     StatusCode = XXXX
  73.  
  74.   Specific replies are mentioned below in section 3, and described more fully
  75.   in section 4.
  76.  
  77. 2.4. General-use tokens
  78.  
  79.   ; Identifiers for servers.
  80.   ServerID = Nickname / Fingerprint
  81.  
  82.   Nickname = 1*19 NicknameChar
  83.   NicknameChar = "a"-"z" / "A"-"Z" / "0" - "9"
  84.   Fingerprint = "$" 40*HEXDIG
  85.  
  86.   ; A "=" indicates that the given nickname is canonical; a "~" indicates
  87.   ; that the given nickname is not canonical.
  88.   LongName = Fingerprint [ ( "=" / "~" ) Nickname ]
  89.  
  90.   ; How a controller tells Tor about a particular OR.  There are four
  91.   ; possible formats:
  92.   ;    $Digest -- The router whose identity key hashes to the given digest.
  93.   ;        This is the preferred way to refer to an OR.
  94.   ;    $Digest~Name -- The router whose identity key hashes to the given
  95.   ;        digest, but only if the router has the given nickname.
  96.   ;    $Digest=Name -- The router whose identity key hashes to the given
  97.   ;        digest, but only if the router is Named and has the given
  98.   ;        nickname.
  99.   ;    Name -- The Named router with the given nickname, or, if no such
  100.   ;        router exists, any router whose nickname matches the one given.
  101.   ;        This is not a safe way to refer to routers, since Named status
  102.   ;        could under some circumstances change over time.
  103.   ServerSpec = LongName / Nickname
  104.  
  105.   ; Unique identifiers for streams or circuits.  Currently, Tor only
  106.   ; uses digits, but this may change
  107.   StreamID = 1*16 IDChar
  108.   CircuitID = 1*16 IDChar
  109.   IDChar = ALPHA / DIGIT
  110.  
  111.   Address = ip4-address / ip6-address / hostname   (XXXX Define these)
  112.  
  113.   ; A "Data" section is a sequence of octets concluded by the terminating
  114.   ; sequence CRLF "." CRLF.  The terminating sequence may not appear in the
  115.   ; body of the data.  Leading periods on lines in the data are escaped with
  116.   ; an additional leading period as in RFC 2821 section 4.5.2.
  117.   Data = *DataLine "." CRLF
  118.   DataLine = CRLF / "." 1*LineItem CRLF / NonDotItem *LineItem CRLF
  119.   LineItem = NonCR / 1*CR NonCRLF
  120.   NonDotItem = NonDotCR / 1*CR NonCRLF
  121.  
  122. 3. Commands
  123.  
  124.   All commands and other keywords are case-insensitive.
  125.  
  126. 3.1. SETCONF
  127.  
  128.   Change the value of one or more configuration variables.  The syntax is:
  129.  
  130.     "SETCONF" 1*(SP keyword ["=" String]) CRLF
  131.  
  132.   Tor behaves as though it had just read each of the key-value pairs
  133.   from its configuration file.  Keywords with no corresponding values have
  134.   their configuration values reset to 0 or NULL (use RESETCONF if you want
  135.   to set it back to its default).  SETCONF is all-or-nothing: if there
  136.   is an error in any of the configuration settings, Tor sets none of them.
  137.  
  138.   Tor responds with a "250 configuration values set" reply on success.
  139.   If some of the listed keywords can't be found, Tor replies with a
  140.   "552 Unrecognized option" message. Otherwise, Tor responds with a
  141.   "513 syntax error in configuration values" reply on syntax error, or a
  142.   "553 impossible configuration setting" reply on a semantic error.
  143.  
  144.   When a configuration option takes multiple values, or when multiple
  145.   configuration keys form a context-sensitive group (see GETCONF below), then
  146.   setting _any_ of the options in a SETCONF command is taken to reset all of
  147.   the others.  For example, if two ORBindAddress values are configured, and a
  148.   SETCONF command arrives containing a single ORBindAddress value, the new
  149.   command's value replaces the two old values.
  150.  
  151. 3.2. RESETCONF
  152.  
  153.   Remove all settings for a given configuration option entirely, assign
  154.   its default value (if any), and then assign the String provided.
  155.   Typically the String is left empty, to simply set an option back to
  156.   its default. The syntax is:
  157.  
  158.     "RESETCONF" 1*(SP keyword ["=" String]) CRLF
  159.  
  160.   Otherwise it behaves like SETCONF above.
  161.  
  162. 3.3. GETCONF
  163.  
  164.   Request the value of a configuration variable.  The syntax is:
  165.  
  166.     "GETCONF" 1*(SP keyword) CRLF
  167.  
  168.   If all of the listed keywords exist in the Tor configuration, Tor replies
  169.   with a series of reply lines of the form:
  170.       250 keyword=value
  171.   If any option is set to a 'default' value semantically different from an
  172.   empty string, Tor may reply with a reply line of the form:
  173.       250 keyword
  174.  
  175.   If some of the listed keywords can't be found, Tor replies with a
  176.   "552 unknown configuration keyword" message.
  177.  
  178.   If an option appears multiple times in the configuration, all of its
  179.   key-value pairs are returned in order.
  180.  
  181.   Some options are context-sensitive, and depend on other options with
  182.   different keywords.  These cannot be fetched directly.  Currently there
  183.   is only one such option: clients should use the "HiddenServiceOptions"
  184.   virtual keyword to get all HiddenServiceDir, HiddenServicePort,
  185.   HiddenServiceNodes, and HiddenServiceExcludeNodes option settings.
  186.  
  187. 3.4. SETEVENTS
  188.  
  189.   Request the server to inform the client about interesting events.  The
  190.   syntax is:
  191.  
  192.      "SETEVENTS" [SP "EXTENDED"] *(SP EventCode) CRLF
  193.  
  194.      EventCode = "CIRC" / "STREAM" / "ORCONN" / "BW" / "DEBUG" /
  195.          "INFO" / "NOTICE" / "WARN" / "ERR" / "NEWDESC" / "ADDRMAP" /
  196.          "AUTHDIR_NEWDESCS" / "DESCCHANGED" / "STATUS_GENERAL" /
  197.          "STATUS_CLIENT" / "STATUS_SERVER" / "GUARDS" / "NS"
  198.  
  199.   Any events *not* listed in the SETEVENTS line are turned off; thus, sending
  200.   SETEVENTS with an empty body turns off all event reporting.
  201.  
  202.   The server responds with a "250 OK" reply on success, and a "552
  203.   Unrecognized event" reply if one of the event codes isn't recognized.  (On
  204.   error, the list of active event codes isn't changed.)
  205.  
  206.   If the flag string "EXTENDED" is provided, Tor may provide extra
  207.   information with events for this connection; see 4.1 for more information.
  208.   NOTE: All events on a given connection will be provided in extended format,
  209.   or none.
  210.   NOTE: "EXTENDED" is only supported in Tor 0.1.1.9-alpha or later.
  211.  
  212.   Each event is described in more detail in Section 4.1.
  213.  
  214. 3.5. AUTHENTICATE
  215.  
  216.   Sent from the client to the server.  The syntax is:
  217.      "AUTHENTICATE" [ SP 1*HEXDIG / QuotedString ] CRLF
  218.  
  219.   The server responds with "250 OK" on success or "515 Bad authentication" if
  220.   the authentication cookie is incorrect.
  221.  
  222.   The format of the 'cookie' is implementation-dependent; see 5.1 below for
  223.   information on how the standard Tor implementation handles it.
  224.  
  225.   If Tor requires authentication and the controller has not yet sent an
  226.   AUTHENTICATE message, Tor sends a "514 authentication required" reply to
  227.   any other kind of message.
  228.  
  229. 3.6. SAVECONF
  230.  
  231.   Sent from the client to the server.  The syntax is:
  232.      "SAVECONF" CRLF
  233.  
  234.   Instructs the server to write out its config options into its torrc. Server
  235.   returns "250 OK" if successful, or "551 Unable to write configuration
  236.   to disk" if it can't write the file or some other error occurs.
  237.  
  238. 3.7. SIGNAL
  239.  
  240.   Sent from the client to the server. The syntax is:
  241.  
  242.      "SIGNAL" SP Signal CRLF
  243.  
  244.      Signal = "RELOAD" / "SHUTDOWN" / "DUMP" / "DEBUG" / "HALT" /
  245.               "HUP" / "INT" / "USR1" / "USR2" / "TERM" / "NEWNYM" /
  246.               "CLEARDNSCACHE"
  247.  
  248.   The meaning of the signals are:
  249.  
  250.       RELOAD    -- Reload: reload config items, refetch directory. (like HUP)
  251.       SHUTDOWN  -- Controlled shutdown: if server is an OP, exit immediately.
  252.                    If it's an OR, close listeners and exit after 30 seconds.
  253.                    (like INT)
  254.       DUMP      -- Dump stats: log information about open connections and
  255.                    circuits. (like USR1)
  256.       DEBUG     -- Debug: switch all open logs to loglevel debug. (like USR2)
  257.       HALT      -- Immediate shutdown: clean up and exit now. (like TERM)
  258.       CLEARDNSCACHE -- Forget the client-side cached IPs for all hostnames.
  259.       NEWNYM    -- Switch to clean circuits, so new application requests
  260.                    don't share any circuits with old ones.  Also clears
  261.                    the client-side DNS cache.
  262.  
  263.   The server responds with "250 OK" if the signal is recognized (or simply
  264.   closes the socket if it was asked to close immediately), or "552
  265.   Unrecognized signal" if the signal is unrecognized.
  266.  
  267. 3.8. MAPADDRESS
  268.  
  269.   Sent from the client to the server.  The syntax is:
  270.  
  271.     "MAPADDRESS" 1*(Address "=" Address SP) CRLF
  272.  
  273.   The first address in each pair is an "original" address; the second is a
  274.   "replacement" address.  The client sends this message to the server in
  275.   order to tell it that future SOCKS requests for connections to the original
  276.   address should be replaced with connections to the specified replacement
  277.   address.  If the addresses are well-formed, and the server is able to
  278.   fulfill the request, the server replies with a 250 message:
  279.     250-OldAddress1=NewAddress1
  280.     250 OldAddress2=NewAddress2
  281.  
  282.   containing the source and destination addresses.  If request is
  283.   malformed, the server replies with "512 syntax error in command
  284.   argument".  If the server can't fulfill the request, it replies with
  285.   "451 resource exhausted".
  286.  
  287.   The client may decline to provide a body for the original address, and
  288.   instead send a special null address ("0.0.0.0" for IPv4, "::0" for IPv6, or
  289.   "." for hostname), signifying that the server should choose the original
  290.   address itself, and return that address in the reply.  The server
  291.   should ensure that it returns an element of address space that is unlikely
  292.   to be in actual use.  If there is already an address mapped to the
  293.   destination address, the server may reuse that mapping.
  294.  
  295.   If the original address is already mapped to a different address, the old
  296.   mapping is removed.  If the original address and the destination address
  297.   are the same, the server removes any mapping in place for the original
  298.   address.
  299.  
  300.   Example:
  301.     C: MAPADDRESS 0.0.0.0=tor.eff.org 1.2.3.4=tor.freehaven.net
  302.     S: 250-127.192.10.10=tor.eff.org
  303.     S: 250 1.2.3.4=tor.freehaven.net
  304.  
  305.   {Note: This feature is designed to be used to help Tor-ify applications
  306.   that need to use SOCKS4 or hostname-less SOCKS5.  There are three
  307.   approaches to doing this:
  308.      1. Somehow make them use SOCKS4a or SOCKS5-with-hostnames instead.
  309.      2. Use tor-resolve (or another interface to Tor's resolve-over-SOCKS
  310.         feature) to resolve the hostname remotely.  This doesn't work
  311.         with special addresses like x.onion or x.y.exit.
  312.      3. Use MAPADDRESS to map an IP address to the desired hostname, and then
  313.         arrange to fool the application into thinking that the hostname
  314.         has resolved to that IP.
  315.   This functionality is designed to help implement the 3rd approach.}
  316.  
  317.   Mappings set by the controller last until the Tor process exits:
  318.   they never expire. If the controller wants the mapping to last only
  319.   a certain time, then it must explicitly un-map the address when that
  320.   time has elapsed.
  321.  
  322. 3.9. GETINFO
  323.  
  324.   Sent from the client to the server.  The syntax is as for GETCONF:
  325.     "GETINFO" 1*(SP keyword) CRLF
  326.   one or more NL-terminated strings.  The server replies with an INFOVALUE
  327.   message, or a 551 or 552 error.
  328.  
  329.   Unlike GETCONF, this message is used for data that are not stored in the Tor
  330.   configuration file, and that may be longer than a single line.  On success,
  331.   one ReplyLine is sent for each requested value, followed by a final 250 OK
  332.   ReplyLine.  If a value fits on a single line, the format is:
  333.       250-keyword=value
  334.   If a value must be split over multiple lines, the format is:
  335.       250+keyword=
  336.       value
  337.       .
  338.   Recognized keys and their values include:
  339.  
  340.     "version" -- The version of the server's software, including the name
  341.       of the software. (example: "Tor 0.0.9.4")
  342.  
  343.     "config-file" -- The location of Tor's configuration file ("torrc").
  344.  
  345.     ["exit-policy/prepend" -- The default exit policy lines that Tor will
  346.       *prepend* to the ExitPolicy config option.
  347.      -- Never implemented. Useful?]
  348.  
  349.     "exit-policy/default" -- The default exit policy lines that Tor will
  350.       *append* to the ExitPolicy config option.
  351.  
  352.     "desc/id/<OR identity>" or "desc/name/<OR nickname>" -- the latest
  353.       server descriptor for a given OR, NUL-terminated.
  354.  
  355.     "ns/id/<OR identity>" or "ns/name/<OR nickname>" -- the latest network
  356.       status info for a given OR.  Network status info is as given in
  357.       dir-spec.txt, and reflects the current beliefs of this Tor about the
  358.       router in question. Like directory clients, controllers MUST
  359.       tolerate unrecognized flags and lines.  The published date and
  360.       descriptor digest are those believed to be best by this Tor,
  361.       not necessarily those for a descriptor that Tor currently has.
  362.       [First implemented in 0.1.2.3-alpha.]
  363.  
  364.     "ns/all" -- Network status info for all ORs we have an opinion about,
  365.       joined by newlines. [First implemented in 0.1.2.3-alpha.]
  366.  
  367.     "desc/all-recent" -- the latest server descriptor for every router that
  368.       Tor knows about.
  369.  
  370.     "network-status" -- a space-separated list of all known OR identities.
  371.       This is in the same format as the router-status line in directories;
  372.       see dir-spec-v1.txt section 3 for details.  (If VERBOSE_NAMES is
  373.       enabled, the output will not conform to dir-spec-v1.txt; instead, the
  374.       result will be a space-separated list of LongName, each preceded by a
  375.       "!" if it is believed to be not running.)
  376.  
  377.     "addr-mappings/all"
  378.     "addr-mappings/config"
  379.     "addr-mappings/cache"
  380.     "addr-mappings/control" -- a space-separated list of address
  381.       mappings, each in the form of "from-address=to-address".
  382.       The 'config' key returns those address mappings set in the
  383.       configuration; the 'cache' key returns the mappings in the
  384.       client-side DNS cache; the 'control' key returns the mappings set
  385.       via the control interface; the 'all' target returns the mappings
  386.       set through any mechanism.
  387.  
  388.     "address" -- the best guess at our external IP address. If we
  389.       have no guess, return a 551 error. (Added in 0.1.2.2-alpha)
  390.  
  391.     "fingerprint" -- the contents of the fingerprint file that Tor
  392.       writes as a server, or a 551 if we're not a server currently.
  393.       (Added in 0.1.2.3-alpha)
  394.  
  395.     "circuit-status"
  396.       A series of lines as for a circuit status event. Each line is of
  397.       the form:
  398.          CircuitID SP CircStatus [SP Path] CRLF
  399.  
  400.     "stream-status"
  401.       A series of lines as for a stream status event.  Each is of the form:
  402.          StreamID SP StreamStatus SP CircID SP Target CRLF
  403.  
  404.     "orconn-status"
  405.       A series of lines as for an OR connection status event.  Each is of the
  406.       form:
  407.          ServerID SP ORStatus CRLF
  408.  
  409.     "entry-guards"
  410.       A series of lines listing the currently chosen entry guards, if any.
  411.       Each is of the form:
  412.          ServerID  SP (Status-with-time / Status) CRLF
  413.  
  414.          Status-with-time = ("down" / "unlisted") SP ISOTime
  415.          Status = ("up" / "never-connected")
  416.  
  417.       [From 0.1.1.4-alpha to 0.1.1.10-alpha, this was called "helper-nodes".
  418.        Tor still supports calling it that for now, but support will be
  419.        removed in 0.1.3.x.]
  420.  
  421.     "accounting/enabled"
  422.     "accounting/hibernating"
  423.     "accounting/bytes"
  424.     "accounting/bytes-left"
  425.     "accounting/interval-start"
  426.     "accounting/interval-wake"
  427.     "accounting/interval-end"
  428.       Information about accounting status.  If accounting is enabled,
  429.       "enabled" is 1; otherwise it is 0.  The "hibernating" field is "hard"
  430.       if we are accepting no data; "soft" if we're accepting no new
  431.       connections, and "awake" if we're not hibernating at all.  The "bytes"
  432.       and "bytes-left" fields contain (read-bytes SP write-bytes), for the
  433.       start and the rest of the interval respectively.  The 'interval-start'
  434.       and 'interval-end' fields are the borders of the current interval; the
  435.       'interval-wake' field is the time within the current interval (if any)
  436.       where we plan[ned] to start being active.
  437.  
  438.     "config/names"
  439.       A series of lines listing the available configuration options. Each is
  440.       of the form:
  441.          OptionName SP OptionType [ SP Documentation ] CRLF
  442.          OptionName = Keyword
  443.          OptionType = "Integer" / "TimeInterval" / "DataSize" / "Float" /
  444.            "Boolean" / "Time" / "CommaList" / "Dependant" / "Virtual" /
  445.            "String" / "LineList"
  446.          Documentation = Text
  447.  
  448.     "info/names"
  449.       A series of lines listing the available GETINFO options.  Each is of
  450.       one of these forms:
  451.          OptionName SP Documentation CRLF
  452.          OptionPrefix SP Documentation CRLF
  453.          OptionPrefix = OptionName "/*"
  454.  
  455.     "events/names"
  456.       A space-separated list of all the events supported by this version of
  457.       Tor's SETEVENTS.
  458.  
  459.     "features/names"
  460.       A space-separated list of all the events supported by this version of
  461.       Tor's USEFEATURE.
  462.  
  463.     "next-circuit/IP:port"
  464.       XXX todo.
  465.  
  466.     "dir/status/authority"
  467.     "dir/status/fp/<F>"
  468.     "dir/status/fp/<F1>+<F2>+<F3>"
  469.     "dir/status/all"
  470.     "dir/server/fp/<F>"
  471.     "dir/server/fp/<F1>+<F2>+<F3>"
  472.     "dir/server/d/<D>"
  473.     "dir/server/d/<D1>+<D2>+<D3>"
  474.     "dir/server/authority"
  475.     "dir/server/all"
  476.       A series of lines listing directory contents, provided according to the
  477.       specification for the URLs listed in Section 4.4 of dir-spec.txt.  Note
  478.       that Tor MUST NOT provide private information, such as descriptors for
  479.       routers not marked as general-purpose.  When asked for 'authority'
  480.       information for which this Tor is not authoritative, Tor replies with
  481.       an empty string.
  482.  
  483.     "status/circuit-established"
  484.     "status/..."
  485.       These provide the current internal Tor values for various Tor
  486.       states. See Section 4.1.10 for explanations. (Only a few of the
  487.       status events are available as getinfo's currently. Let us know if
  488.       you want more exposed.)
  489.  
  490.   Examples:
  491.      C: GETINFO version desc/name/moria1
  492.      S: 250+desc/name/moria=
  493.      S: [Descriptor for moria]
  494.      S: .
  495.      S: 250-version=Tor 0.1.1.0-alpha-cvs
  496.      S: 250 OK
  497.  
  498. 3.10. EXTENDCIRCUIT
  499.  
  500.   Sent from the client to the server.  The format is:
  501.       "EXTENDCIRCUIT" SP CircuitID SP
  502.                       ServerSpec *("," ServerSpec) SP
  503.                       ("purpose=" Purpose) CRLF
  504.  
  505.   This request takes one of two forms: either the CircuitID is zero, in
  506.   which case it is a request for the server to build a new circuit according
  507.   to the specified path, or the CircuitID is nonzero, in which case it is a
  508.   request for the server to extend an existing circuit with that ID according
  509.   to the specified path.
  510.  
  511.   If CircuitID is 0 and "purpose=" is specified, then the circuit's
  512.   purpose is set. Two choices are recognized: "general" and
  513.   "controller". If not specified, circuits are created as "general".
  514.  
  515.   If the request is successful, the server sends a reply containing a
  516.   message body consisting of the CircuitID of the (maybe newly created)
  517.   circuit. The syntax is "250" SP "EXTENDED" SP CircuitID CRLF.
  518.  
  519. 3.11. SETCIRCUITPURPOSE
  520.  
  521.   Sent from the client to the server.  The format is:
  522.       "SETCIRCUITPURPOSE" SP CircuitID SP Purpose CRLF
  523.  
  524.   This changes the circuit's purpose. See EXTENDCIRCUIT above for details.
  525.  
  526. 3.12. SETROUTERPURPOSE
  527.  
  528.   Sent from the client to the server.  The format is:
  529.       "SETROUTERPURPOSE" SP NicknameOrKey SP Purpose CRLF
  530.  
  531.   This changes the descriptor's purpose. See +POSTDESCRIPTOR below
  532.   for details.
  533.  
  534. 3.13. ATTACHSTREAM
  535.  
  536.   Sent from the client to the server.  The syntax is:
  537.      "ATTACHSTREAM" SP StreamID SP CircuitID CRLF
  538.  
  539.   This message informs the server that the specified stream should be
  540.   associated with the specified circuit.  Each stream may be associated with
  541.   at most one circuit, and multiple streams may share the same circuit.
  542.   Streams can only be attached to completed circuits (that is, circuits that
  543.   have sent a circuit status 'BUILT' event or are listed as built in a
  544.   GETINFO circuit-status request).
  545.  
  546.   If the circuit ID is 0, responsibility for attaching the given stream is
  547.   returned to Tor.
  548.  
  549.   Tor responds with "250 OK" if it can attach the stream, 552 if the circuit
  550.   or stream didn't exist, or 551 if the stream couldn't be attached for
  551.   another reason.
  552.  
  553.   {Implementation note: Tor will close unattached streams by itself,
  554.   roughly two minutes after they are born. Let the developers know if
  555.   that turns out to be a problem.}
  556.  
  557.   {Implementation note: By default, Tor automatically attaches streams to
  558.   circuits itself, unless the configuration variable
  559.   "__LeaveStreamsUnattached" is set to "1".  Attempting to attach streams
  560.   via TC when "__LeaveStreamsUnattached" is false may cause a race between
  561.   Tor and the controller, as both attempt to attach streams to circuits.}
  562.  
  563.   {Implementation note: You can try to attachstream to a stream that
  564.   has already sent a connect or resolve request but hasn't succeeded
  565.   yet, in which case Tor will detach the stream from its current circuit
  566.   before proceeding with the new attach request.}
  567.  
  568. 3.14. POSTDESCRIPTOR
  569.  
  570.   Sent from the client to the server. The syntax is:
  571.     "+POSTDESCRIPTOR" ("purpose=" Purpose) CRLF Descriptor CRLF "." CRLF
  572.  
  573.   This message informs the server about a new descriptor. If Purpose is
  574.   specified, it must be either "general" or "controller", else we
  575.   return a 552 error.
  576.  
  577.   The descriptor, when parsed, must contain a number of well-specified
  578.   fields, including fields for its nickname and identity.
  579.  
  580.   If there is an error in parsing the descriptor, the server must send a "554
  581.   Invalid descriptor" reply.  If the descriptor is well-formed but the server
  582.   chooses not to add it, it must reply with a 251 message whose body explains
  583.   why the server was not added.  If the descriptor is added, Tor replies with
  584.   "250 OK".
  585.  
  586. 3.15. REDIRECTSTREAM
  587.  
  588.   Sent from the client to the server. The syntax is:
  589.     "REDIRECTSTREAM" SP StreamID SP Address (SP Port) CRLF
  590.  
  591.   Tells the server to change the exit address on the specified stream.  If
  592.   Port is specified, changes the destination port as well.  No remapping
  593.   is performed on the new provided address.
  594.  
  595.   To be sure that the modified address will be used, this event must be sent
  596.   after a new stream event is received, and before attaching this stream to
  597.   a circuit.
  598.  
  599.   Tor replies with "250 OK" on success.
  600.  
  601. 3.16. CLOSESTREAM
  602.  
  603.   Sent from the client to the server.  The syntax is:
  604.  
  605.     "CLOSESTREAM" SP StreamID SP Reason *(SP Flag) CRLF
  606.  
  607.   Tells the server to close the specified stream.  The reason should be one
  608.   of the Tor RELAY_END reasons given in tor-spec.txt, as a decimal.  Flags is
  609.   not used currently; Tor servers SHOULD ignore unrecognized flags.  Tor may
  610.   hold the stream open for a while to flush any data that is pending.
  611.  
  612.   Tor replies with "250 OK" on success, or a 512 if there aren't enough
  613.   arguments, or a 552 if it doesn't recognize the StreamID or reason.
  614.  
  615. 3.17. CLOSECIRCUIT
  616.  
  617.    The syntax is:
  618.      CLOSECIRCUIT SP CircuitID *(SP Flag) CRLF
  619.      Flag = "IfUnused"
  620.  
  621.   Tells the server to close the specified circuit.   If "IfUnused" is
  622.   provided, do not close the circuit unless it is unused.
  623.  
  624.   Other flags may be defined in the future; Tor SHOULD ignore unrecognized
  625.   flags.
  626.  
  627.   Tor replies with "250 OK" on success, or a 512 if there aren't enough
  628.   arguments, or a 552 if it doesn't recognize the CircuitID.
  629.  
  630. 3.18. QUIT
  631.  
  632.   Tells the server to hang up on this controller connection. This command
  633.   can be used before authenticating.
  634.  
  635. 3.19. USEFEATURE
  636.  
  637.   The syntax is:
  638.  
  639.     "USEFEATURE" *(SP FeatureName) CRLF
  640.     FeatureName = 1*(ALPHA / DIGIT / "_" / "-")
  641.  
  642.   Sometimes extensions to the controller protocol break compatibility with
  643.   older controllers.  In this case, whenever possible, the extensions are
  644.   first included in Tor disabled by default, and only enabled on a given
  645.   controller connection when the "USEFEATURE" command is given.  Once a
  646.   "USEFEATURE" command is given, it applies to all subsequent interactions on
  647.   the same connection; to disable an enabled feature, a new controller
  648.   connection must be opened.
  649.  
  650.   This is a forward-compatibility mechanism; each feature will eventually
  651.   become a regular part of the control protocol in some future version of Tor.
  652.   Tor will ignore a request to use any feature that is already on by default.
  653.   Tor will give a "552" error if any requested feature is not recognized.
  654.  
  655.   Feature names are case-insensitive.
  656.  
  657.   EXTENDED_EVENTS
  658.  
  659.      Same as passing 'EXTENDED' to SETEVENTS; this is the preferred way to
  660.      request the extended event syntax.
  661.  
  662.      This will not be always-enabled until at least XXX (or, at least two
  663.      stable releases after XXX, the release where it was first used for
  664.      anything.)
  665.  
  666.   VERBOSE_NAMES
  667.  
  668.      Instead of ServerID as specified above, the controller should
  669.      identify ORs by LongName in events and GETINFO results.  This format is
  670.      strictly more informative: rather than including Nickname for
  671.      known Named routers and Fingerprint for unknown or unNamed routers, the
  672.      LongName format includes a Fingerprint, an indication of Named status,
  673.      and a Nickname (if one is known).
  674.  
  675.      This will not be always-enabled until at least 0.1.4.x (or at least two
  676.      stable releases after 0.1.2.2-alpha, the release where it was first
  677.      available.)
  678.  
  679. 4. Replies
  680.  
  681.   Reply codes follow the same 3-character format as used by SMTP, with the
  682.   first character defining a status, the second character defining a
  683.   subsystem, and the third designating fine-grained information.
  684.  
  685.   The TC protocol currently uses the following first characters:
  686.  
  687.     2yz   Positive Completion Reply
  688.        The command was successful; a new request can be started.
  689.  
  690.     4yz   Temporary Negative Completion reply
  691.        The command was unsuccessful but might be reattempted later.
  692.  
  693.     5yz   Permanent Negative Completion Reply
  694.        The command was unsuccessful; the client should not try exactly
  695.        that sequence of commands again.
  696.  
  697.     6yz   Asynchronous Reply
  698.        Sent out-of-order in response to an earlier SETEVENTS command.
  699.  
  700.   The following second characters are used:
  701.  
  702.     x0z   Syntax
  703.        Sent in response to ill-formed or nonsensical commands.
  704.  
  705.     x1z   Protocol
  706.        Refers to operations of the Tor Control protocol.
  707.  
  708.     x5z   Tor
  709.        Refers to actual operations of Tor system.
  710.  
  711.   The following codes are defined:
  712.  
  713.      250 OK
  714.      251 Operation was unnecessary
  715.          [Tor has declined to perform the operation, but no harm was done.]
  716.  
  717.      451 Resource exhausted
  718.  
  719.      500 Syntax error: protocol
  720.  
  721.      510 Unrecognized command
  722.      511 Unimplemented command
  723.      512 Syntax error in command argument
  724.      513 Unrecognized command argument
  725.      514 Authentication required
  726.      515 Bad authentication
  727.  
  728.      550 Unspecified Tor error
  729.  
  730.      551 Internal error
  731.                [Something went wrong inside Tor, so that the client's
  732.                 request couldn't be fulfilled.]
  733.  
  734.      552 Unrecognized entity
  735.                [A configuration key, a stream ID, circuit ID, event,
  736.                 mentioned in the command did not actually exist.]
  737.  
  738.      553 Invalid configuration value
  739.          [The client tried to set a configuration option to an
  740.            incorrect, ill-formed, or impossible value.]
  741.  
  742.      554 Invalid descriptor
  743.  
  744.      555 Unmanaged entity
  745.  
  746.      650 Asynchronous event notification
  747.  
  748.   Unless specified to have specific contents, the human-readable messages
  749.   in error replies should not be relied upon to match those in this document.
  750.  
  751. 4.1. Asynchronous events
  752.  
  753.   These replies can be sent after a corresponding SETEVENTS command has been
  754.   received.  They will not be interleaved with other Reply elements, but they
  755.   can appear between a command and its corresponding reply.  For example,
  756.   this sequence is possible:
  757.  
  758.      C: SETEVENTS CIRC
  759.      S: 250 OK
  760.      C: GETCONF SOCKSPORT ORPORT
  761.      S: 650 CIRC 1000 EXTENDED moria1,moria2
  762.      S: 250-SOCKSPORT=9050
  763.      S: 250 ORPORT=0
  764.  
  765.   But this sequence is disallowed:
  766.      C: SETEVENTS CIRC
  767.      S: 250 OK
  768.      C: GETCONF SOCKSPORT ORPORT
  769.      S: 250-SOCKSPORT=9050
  770.      S: 650 CIRC 1000 EXTENDED moria1,moria2
  771.      S: 250 ORPORT=0
  772.  
  773.   Clients MUST tolerate more arguments in an asynchonous reply than
  774.   expected, and MUST tolerate more lines in an asynchronous reply than
  775.   expected.  For instance, a client that expects a CIRC message like:
  776.       650 CIRC 1000 EXTENDED moria1,moria2
  777.   must tolerate:
  778.       650-CIRC 1000 EXTENDED moria1,moria2 0xBEEF
  779.       650-EXTRAMAGIC=99
  780.       650 ANONYMITY=high
  781.  
  782.   If clients ask for extended events, then each event line as specified below
  783.   will be followed by additional extensions. Additional lines will be of the
  784.   form
  785.       "650" ("-"/" ") KEYWORD ["=" ARGUMENTS] CRLF
  786.   Additional arguments will be of the form
  787.       SP KEYWORD ["=" ( QuotedString / * NonSpDquote ) ]
  788.   Such clients MUST tolerate lines with keywords they do not recognize.
  789.  
  790. 4.1.1. Circuit status changed
  791.  
  792.    The syntax is:
  793.  
  794.      "650" SP "CIRC" SP CircuitID SP CircStatus [SP Path]
  795.           [SP "REASON=" Reason [SP "REMOTE_REASON=" Reason]] CRLF
  796.  
  797.       CircStatus =
  798.                "LAUNCHED" / ; circuit ID assigned to new circuit
  799.                "BUILT"    / ; all hops finished, can now accept streams
  800.                "EXTENDED" / ; one more hop has been completed
  801.                "FAILED"   / ; circuit closed (was not built)
  802.                "CLOSED"     ; circuit closed (was built)
  803.  
  804.       Path = ServerID *("," ServerID)
  805.  
  806.       Reason = "NONE" / "TORPROTOCOL" / "INTERNAL" / "REQUESTED" /
  807.                "HIBERNATING" / "RESOURCELIMIT" / "CONNECTFAILED" /
  808.                "OR_IDENTITY" / "OR_CONN_CLOSED" / "TIMEOUT" /
  809.                "FINISHED" / "DESTROYED" / "NOPATH" / "NOSUCHSERVICE"
  810.  
  811.    The path is provided only when the circuit has been extended at least one
  812.    hop.
  813.  
  814.    The "REASON" field is provided only for FAILED and CLOSED events, and only
  815.    if extended events are enabled (see 3.19).  Clients MUST accept reasons
  816.    not listed above.  Reasons are as given in tor-spec.txt, except for:
  817.  
  818.       NOPATH          (Not enough nodes to make circuit)
  819.  
  820.    The "REMOTE_REASON" field is provided only when we receive a DESTROY or
  821.    TRUNCATE cell, and only if extended events are enabled.  It contains the
  822.    actual reason given by the remote OR for closing the circuit. Clients MUST
  823.    accept reasons not listed above.  Reasons are as listed in tor-spec.txt.
  824.  
  825. 4.1.2. Stream status changed
  826.  
  827.     The syntax is:
  828.  
  829.       "650" SP "STREAM" SP StreamID SP StreamStatus SP CircID SP Target
  830.           [SP "REASON=" Reason [ SP "REMOTE_REASON=" Reason ]] CRLF
  831.  
  832.       StreamStatus =
  833.                "NEW"          / ; New request to connect
  834.                "NEWRESOLVE"   / ; New request to resolve an address
  835.                "REMAP"        / ; Address re-mapped to another
  836.                "SENTCONNECT"  / ; Sent a connect cell along a circuit
  837.                "SENTRESOLVE"  / ; Sent a resolve cell along a circuit
  838.                "SUCCEEDED"    / ; Received a reply; stream established
  839.                "FAILED"       / ; Stream failed and not retriable
  840.                "CLOSED"       / ; Stream closed
  841.                "DETACHED"       ; Detached from circuit; still retriable
  842.  
  843.        Target = Address ":" Port
  844.  
  845.   The circuit ID designates which circuit this stream is attached to.  If
  846.   the stream is unattached, the circuit ID "0" is given.
  847.  
  848.       Reason = "MISC" / "RESOLVEFAILED" / "CONNECTREFUSED" /
  849.                "EXITPOLICY" / "DESTROY" / "DONE" / "TIMEOUT" /
  850.                "HIBERNATING" / "INTERNAL"/ "RESOURCELIMIT" /
  851.                "CONNRESET" / "TORPROTOCOL" / "NOTDIRECTORY" / "END"
  852.  
  853.    The "REASON" field is provided only for FAILED, CLOSED, and DETACHED
  854.    events, and only if extended events are enabled (see 3.19).  Clients MUST
  855.    accept reasons not listed above.  Reasons are as given in tor-spec.txt,
  856.    except for:
  857.  
  858.       END          (We received a RELAY_END cell from the other side of thise
  859.                     stream.)
  860.  
  861.    The "REMOTE_REASON" field is provided only when we receive a RELAY_END
  862.    cell, and only if extended events are enabled.  It contains the actual
  863.    reason given by the remote OR for closing the stream. Clients MUST accept
  864.    reasons not listed above.  Reasons are as listed in tor-spec.txt.
  865.  
  866. 4.1.3. OR Connection status changed
  867.  
  868.   The syntax is:
  869.     "650" SP "ORCONN" SP (ServerID / Target) SP ORStatus [ SP "REASON="
  870.              Reason ] [ SP "NCIRCS=" NumCircuits ]
  871.  
  872.     ORStatus = "NEW" / "LAUNCHED" / "CONNECTED" / "FAILED" / "CLOSED"
  873.  
  874.   NEW is for incoming connections, and LAUNCHED is for outgoing
  875.   connections. CONNECTED means the TLS handshake has finished (in
  876.   either direction). FAILED means a connection is being closed that
  877.   hasn't finished its handshake, and CLOSED is for connections that
  878.   have handshaked.
  879.  
  880.   A ServerID is specified unless it's a NEW connection, in which
  881.   case we don't know what server it is yet, so we use Address:Port.
  882.  
  883.   If extended events are enabled (see 3.19), optional reason and
  884.   circuit counting information is provided for CLOSED and FAILED
  885.   events. 
  886.  
  887.       Reason = "MISC" / "DONE" / "CONNECTREFUSED" /
  888.                "IDENTITY" / "CONNECTRESET" / "TIMEOUT" / "NOROUTE" /
  889.                "IOERROR" 
  890.  
  891.   NumCircuits counts both established and pending circuits.
  892.  
  893.  
  894. 4.1.4. Bandwidth used in the last second
  895.  
  896.   The syntax is:
  897.      "650" SP "BW" SP BytesRead SP BytesWritten *(SP Type "=" Num)
  898.      BytesRead = 1*DIGIT
  899.      BytesWritten = 1*DIGIT
  900.      Type = "DIR" / "OR" / "EXIT" / "APP" / ...
  901.      Num = 1*DIGIT
  902.  
  903.   BytesRead and BytesWritten are the totals. In Tor 0.1.x.y-alpha
  904.   and later, we also include a breakdown of the connection types
  905.   that used bandwidth this second (not implemented yet).
  906.  
  907. 4.1.5. Log messages
  908.  
  909.   The syntax is:
  910.      "650" SP Severity SP ReplyText
  911.   or
  912.      "650+" Severity CRLF Data
  913.  
  914.      Severity = "DEBUG" / "INFO" / "NOTICE" / "WARN"/ "ERR"
  915.  
  916. 4.1.6. New descriptors available
  917.  
  918.   Syntax:
  919.      "650" SP "NEWDESC" 1*(SP ServerID)
  920.  
  921. 4.1.7. New Address mapping
  922.  
  923.   Syntax:
  924.      "650" SP "ADDRMAP" SP Address SP Address SP Expiry
  925.      Expiry = DQUOTE ISOTime DQUOTE / "NEVER"
  926.  
  927.   Expiry is expressed as the local time (rather than GMT).
  928.  
  929.   [XXX We should rename this to ADDRESSMAP. -RD]
  930.  
  931.   [FFF We should add a SOURCE=%s argument for extended events,
  932.    which specifies what exit node told us this addressmap. -RD]
  933.  
  934. 4.1.8. Descriptors uploaded to us in our role as authoritative dirserver
  935.  
  936.   Syntax:
  937.      "650" "+" "AUTHDIR_NEWDESCS" CRLF Action CRLF Message CRLF
  938.        Descriptor CRLF "." CRLF
  939.      Action = "ACCEPTED" / "DROPPED" / "REJECTED"
  940.      Message = Text
  941.  
  942. 4.1.9. Our descriptor changed
  943.  
  944.   Syntax:
  945.      "650" SP "DESCCHANGED"
  946.  
  947.   [First added in 0.1.2.2-alpha.]
  948.  
  949. 4.1.10. Status events
  950.  
  951.   Status events (STATUS_GENERAL, STATUS_CLIENT, and STATUS_SERVER) are sent
  952.   based on occurrences in the Tor process pertaining to the general state of
  953.   the program.  Generally, they correspond to log messages of severity Notice
  954.   or higher.  They differ from log messages in that their format is a
  955.   specified interface.
  956.  
  957.   Syntax:
  958.      "650" SP StatusType SP StatusSeverity SP StatusAction
  959.                                          [SP StatusArguments] CRLF
  960.  
  961.      StatusType = "STATUS_GENERAL" / "STATUS_CLIENT" / "STATUS_SERVER"
  962.      StatusSeverity = "NOTICE" / "WARN" / "ERR"
  963.      StatusAction = 1*ALPHA
  964.      StatusArguments = StatusArgument *(SP StatusArgument)
  965.      StatusArgument = StatusKeyword '=' StatusValue
  966.      StatusKeyword = 1*(ALNUM / "_")
  967.      StatusValue = 1*(ALNUM / '_')  / QuotedString
  968.  
  969.      Action is a string, and Arguments is a series of keyword=value
  970.      pairs on the same line.  Values may be space-terminated strings,
  971.      or quoted strings.
  972.  
  973.      These events are always produced with EXTENDED_EVENTS and
  974.      VERBOSE_NAMES; see the explanations in the USEFEATURE section
  975.      for details.
  976.  
  977.      Controllers MUST tolerate unrecognized actions, MUST tolerate
  978.      unrecognized arguments, MUST tolerate missing arguments, and MUST
  979.      tolerate arguments that arrive in any order.
  980.  
  981.      Each event description below is accompanied by a recommendation for
  982.      controllers.  These recommendations are suggestions only; no controller
  983.      is required to implement them.
  984.  
  985.   Actions for STATUS_GENERAL events can be as follows:
  986.  
  987.      CLOCK_JUMPED
  988.      "TIME=NUM"
  989.        Tor spent enough time without CPU cycles that it has closed all
  990.        its circuits and will establish them anew. This typically
  991.        happens when a laptop goes to sleep and then wakes up again. It
  992.        also happens when the system is swapping so heavily that Tor is
  993.        starving. The "time" argument specifies the number of seconds Tor
  994.        thinks it was unconscious for (or alternatively, the number of
  995.        seconds it went back in time).
  996.  
  997.        This status event is sent as NOTICE severity normally, but WARN
  998.        severity if Tor is acting as a server currently.
  999.  
  1000.        {Recommendation for controller: ignore it, since we don't really
  1001.        know what the user should do anyway. Hm.}
  1002.  
  1003.      DANGEROUS_VERSION
  1004.      "CURRENT=version"
  1005.      "REASON=NEW/OLD/UNRECOMMENDED"
  1006.      "RECOMMENDED=\"version, version, ...\""
  1007.        Tor has found that directory servers don't recommend its version of
  1008.        the Tor software.  RECOMMENDED is a comma-and-space-separated string
  1009.        of Tor versions that are recommended.  REASON is NEW if this version
  1010.        of Tor is newer than any recommended version, OLD if this version of
  1011.        Tor is older than any recommended version, and UNRECOMMENDED if
  1012.        some recommended versions of Tor are newer and some are old than this
  1013.        version.
  1014.  
  1015.        {Controllers may want to suggest that the user upgrade OLD or
  1016.        UNRECOMMENDED versions.  NEW versions may be known-insecure, or may
  1017.        simply be development versions.}
  1018.  
  1019.      TOO_MANY_CONNECTIONS
  1020.      "CURRENT=NUM"
  1021.        Tor has reached its ulimit -n or whatever the native limit is on file
  1022.        descriptors or sockets.  CURRENT is the number of sockets Tor
  1023.        currently has open.  The user should really do something about
  1024.        this. The "current" argument shows the number of connections currently
  1025.        open.
  1026.  
  1027.        {Controllers may recommend that the user increase the limit, or
  1028.        increase it for them.  Recommendations should be phrased in an
  1029.        OS-appropriate way and automated when possible.}
  1030.  
  1031.      BUG
  1032.      "REASON=STRING"
  1033.        Tor has encountered a situation that its developers never expected,
  1034.        and the developers would like to learn that it happened. Perhaps
  1035.        the controller can explain this to the user and encourage her to
  1036.        file a bug report?
  1037.  
  1038.        {Controllers should log bugs, but shouldn't annoy the user in case a
  1039.        bug appears frequently.}
  1040.  
  1041.      CLOCK_SKEWED
  1042.        SKEW="+" / "-" SECONDS
  1043.        SOURCE="DIRSERV:IP:Port" / "NETWORKSTATUS:IP:PORT"
  1044.          If "SKEW" is present, it's an estimate of how far we are from the
  1045.          time declared in the source.  If the source is a DIRSERV, we got
  1046.          the current time from a connection to a dirserver.  If the source is
  1047.          a NETWORKSTATUS, we decided we're skewed because we got a
  1048.          networkstatus from far in the future.
  1049.  
  1050.          {Controllers may want to warn the user if the skew is high, or if
  1051.          multiple skew messages appear at severity WARN.  Controllers
  1052.          shouldn't blindly adjust the clock, since the more accurate source
  1053.          of skew info (DIRSERV) is currently unauthenticated.}
  1054.  
  1055.      BAD_LIBEVENT
  1056.      "METHOD=" libevent method
  1057.      "VERSION=" libevent version
  1058.      "BADNESS=" "BROKEN" / "BUGGY" / "SLOW"
  1059.      "RECOVERED=" "NO" / "YES"
  1060.         Tor knows about bugs in using the configured event method in this
  1061.         version of libevent.  "BROKEN" libevents won't work at all;
  1062.         "BUGGY" libevents might work okay; "SLOW" libevents will work
  1063.         fine, but not quickly.  If "RECOVERED" is YES, Tor managed to
  1064.         switch to a more reliable (but probably slower!) libevent method.
  1065.  
  1066.         {Controllers may want to warn the user if this event occurs, though
  1067.         generally it's the fault of whoever built the Tor binary and there's
  1068.         not much the user can do besides upgrade libevent or upgrade the
  1069.         binary.}
  1070.  
  1071.      DIR_ALL_UNREACHABLE
  1072.        Tor believes that none of the known directory servers are
  1073.        reachable -- this is most likely because the local network is
  1074.        down or otherwise not working, and might help to explain for the
  1075.        user why Tor appears to be broken.
  1076.  
  1077.        {Controllers may want to warn the user if this event occurs; further
  1078.        action is generally not possible.}
  1079.  
  1080.   Actions for STATUS_CLIENT events can be as follows:
  1081.  
  1082.      ENOUGH_DIR_INFO
  1083.        Tor now knows enough network-status documents and enough server
  1084.        descriptors that it's going to start trying to build circuits now.
  1085.  
  1086.        {Controllers may want to use this event to decide when to indicate
  1087.        progress to their users, but should not interrupt the user's browsing
  1088.        to tell them so.}
  1089.  
  1090.      NOT_ENOUGH_DIR_INFO
  1091.        We discarded expired statuses and router descriptors to fall
  1092.        below the desired threshold of directory information. We won't
  1093.        try to build any circuits until ENOUGH_DIR_INFO occurs again.
  1094.  
  1095.        {Controllers may want to use this event to decide when to indicate
  1096.        progress to their users, but should not interrupt the user's browsing
  1097.        to tell them so.}
  1098.  
  1099.      CIRCUIT_ESTABLISHED
  1100.        Tor is able to establish circuits for client use. This event will
  1101.        only be sent if we just built a circuit that changed our mind --
  1102.        that is, prior to this event we didn't know whether we could
  1103.        establish circuits.
  1104.  
  1105.        {Suggested use: controllers can notify their users that Tor is
  1106.        ready for use as a client once they see this status event. [Perhaps
  1107.        controllers should also have a timeout if too much time passes and
  1108.        this event hasn't arrived, to give tips on how to troubleshoot.
  1109.        On the other hand, hopefully Tor will send further status events
  1110.        if it can identify the problem.]}
  1111.  
  1112.      CIRCUIT_NOT_ESTABLISHED
  1113.      "REASON=" "EXTERNAL_ADDRESS" / "DIR_ALL_UNREACHABLE" / "CLOCK_JUMPED"
  1114.        We are no longer confident that we can build circuits. The "reason"
  1115.        keyword provides an explanation: which other status event type caused
  1116.        our lack of confidence.
  1117.  
  1118.        {Controllers may want to use this event to decide when to indicate
  1119.        progress to their users, but should not interrupt the user's browsing
  1120.        to do so.}
  1121.        [Note: only REASON=CLOCK_JUMPED is implemented currently.]
  1122.  
  1123.      DANGEROUS_SOCKS
  1124.      "PROTOCOL=SOCKS4/SOCKS5"
  1125.      "ADDRESS=IP:port"
  1126.        A connection was made to Tor's SOCKS port using one of the SOCKS
  1127.        approaches that doesn't support hostnames -- only raw IP addresses.
  1128.        If the client application got this address from gethostbyname(),
  1129.        it may be leaking target addresses via DNS.
  1130.  
  1131.        {Controllers should warn their users when this occurs, unless they
  1132.        happen to know that the application using Tor is in fact doing so
  1133.        correctly (e.g., because it is part of a distributed bundle).}
  1134.  
  1135.      SOCKS_UNKNOWN_PROTOCOL
  1136.        "DATA=string"
  1137.        A connection was made to Tor's SOCKS port that tried to use it
  1138.        for something other than the SOCKS protocol. Perhaps the user is
  1139.        using Tor as an HTTP proxy?   The DATA is the first few characters
  1140.        sent to Tor on the SOCKS port.
  1141.  
  1142.        {Controllers may want to warn their users when this occurs: it
  1143.        indicates a misconfigured application.}
  1144.  
  1145.      SOCKS_BAD_HOSTNAME
  1146.       "HOSTNAME=QuotedString"
  1147.        Some application gave us a funny-looking hostname. Perhaps
  1148.        it is broken? In any case it won't work with Tor and the user
  1149.        should know.
  1150.  
  1151.        {Controllers may want to warn their users when this occurs: it
  1152.        usually indicates a misconfigured application.}
  1153.  
  1154.   Actions for STATUS_SERVER can be as follows:
  1155.  
  1156.      EXTERNAL_ADDRESS
  1157.      "ADDRESS=IP"
  1158.      "HOSTNAME=NAME"
  1159.      "METHOD=CONFIGURED/DIRSERV/RESOLVED/INTERFACE/GETHOSTNAME"
  1160.        Our best idea for our externally visible IP has changed to 'IP'.
  1161.        If 'HOSTNAME' is present, we got the new IP by resolving 'NAME'.  If the
  1162.        method is 'CONFIGURED', the IP was given verbatim as a configuration
  1163.        option.  If the method is 'RESOLVED', we resolved the Address
  1164.        configuration option to get the IP.  If the method is 'GETHOSTNAME',
  1165.        we resolved our hostname to get the IP.  If the method is 'INTERFACE',
  1166.        we got the address of one of our network interfaces to get the IP.  If
  1167.        the method is 'DIRSERV', a directory server told us a guess for what
  1168.        our IP might be.
  1169.  
  1170.        {Controllers may want to record this info and display it to the user.}
  1171.  
  1172.      CHECKING_REACHABILITY
  1173.      "ORADDRESS=IP:port"
  1174.      "DIRADDRESS=IP:port"
  1175.        We're going to start testing the reachability of our external OR port
  1176.        or directory port.
  1177.  
  1178.        {This event could effect the controller's idea of server status, but
  1179.        the controller should not interrupt the user to tell them so.}
  1180.  
  1181.      REACHABILITY_SUCCEEDED
  1182.      "ORADDRESS=IP:port"
  1183.      "DIRADDRESS=IP:port"
  1184.        We successfully verified the reachability of our external OR port or
  1185.        directory port.
  1186.  
  1187.        {This event could effect the controller's idea of server status, but
  1188.        the controller should not interrupt the user to tell them so.}
  1189.  
  1190.      GOOD_SERVER_DESCRIPTOR
  1191.        We successfully uploaded our server descriptor to each of the
  1192.        directory authorities, with no complaints.
  1193.  
  1194.        {This event could effect the controller's idea of server status, but
  1195.        the controller should not interrupt the user to tell them so.}
  1196.  
  1197.      NAMESERVER_STATUS
  1198.      "NS=addr"
  1199.      "STATUS=" "UP" / "DOWN"
  1200.      "ERR=" message
  1201.         One of our nameservers has changed status.
  1202.         // actually notice
  1203.  
  1204.        {This event could effect the controller's idea of server status, but
  1205.        the controller should not interrupt the user to tell them so.}
  1206.  
  1207.      NAMESERVER_ALL_DOWN
  1208.         All of our nameservers have gone down.
  1209.  
  1210.         {This is a problem; if it happens often without the nameservers
  1211.         coming up again, the user needs to configure more or better
  1212.         nameservers.}
  1213.  
  1214.      DNS_HIJACKED
  1215.         Our DNS provider is providing an address when it should be saying
  1216.         "NOTFOUND"; Tor will treat the address as a synonym for "NOTFOUND".
  1217.  
  1218.         {This is an annoyance; controllers may want to tell admins that their
  1219.         DNS provider is not to be trusted.}
  1220.  
  1221.      DNS_USELESS
  1222.         Our DNS provider is giving a hijacked address instead of well-known
  1223.         websites; Tor will not try to be an exit node.
  1224.  
  1225.         {Controllers could warn the admin if the server is running as an
  1226.         exit server: the admin needs to configure a good DNS server.
  1227.         Alternatively, this happens a lot in some restrictive environments
  1228.         (hotels, universities, coffeeshops) when the user hasn't registered.}
  1229.  
  1230.      BAD_SERVER_DESCRIPTOR
  1231.      "DIRAUTH=addr:port"
  1232.      "REASON=string"
  1233.         A directory authority rejected our descriptor.  Possible reasons
  1234.         include malformed descriptors, incorrect keys, highly skewed clocks,
  1235.         and so on.
  1236.  
  1237.         {Controllers should warn the admin, and try to cope if they can.}
  1238.  
  1239.      ACCEPTED_SERVER_DESCRIPTOR
  1240.      "DIRAUTH=addr:port"
  1241.         A single directory authority accepted our descriptor.
  1242.         // actually notice
  1243.  
  1244.        {This event could effect the controller's idea of server status, but
  1245.        the controller should not interrupt the user to tell them so.}
  1246.  
  1247.      REACHABILITY_FAILED
  1248.      "ORADDRESS=IP:port"
  1249.      "DIRADDRESS=IP:port"
  1250.        We failed to connect to our external OR port or directory port
  1251.        successfully.
  1252.  
  1253.        {This event could effect the controller's idea of server status.  The
  1254.        controller should warn the admin and suggest reasonable steps to take.}
  1255.  
  1256. 4.1.11. Our set of guard nodes has changed
  1257.  
  1258.   Syntax:
  1259.      "650" SP "GUARDS" SP Type SP Name SP Status ... CRLF
  1260.      Type = "ENTRY"
  1261.      Name = The (possibly verbose) nickname of the guard affected.
  1262.      Status = "NEW" | "UP" | "DOWN" | "BAD" | "GOOD" | "DROPPED"
  1263.  
  1264.   [explain states. XXX]
  1265.  
  1266. 4.1.12. Network status has changed
  1267.  
  1268.   Syntax:
  1269.      "650" "+" "NS" CRLF  1*NetworkStatus "." CRLF
  1270.  
  1271.   [First added in 0.1.2.3-alpha]
  1272.  
  1273. 5. Implementation notes
  1274.  
  1275. 5.1. Authentication
  1276.  
  1277.   By default, the current Tor implementation trusts all local users.
  1278.  
  1279.   If the 'CookieAuthentication' option is true, Tor writes a "magic cookie"
  1280.   file named "control_auth_cookie" into its data directory.  To authenticate,
  1281.   the controller must send the contents of this file, encoded in hexadecimal.
  1282.  
  1283.   If the 'HashedControlPassword' option is set, it must contain the salted
  1284.   hash of a secret password.  The salted hash is computed according to the
  1285.   S2K algorithm in RFC 2440 (OpenPGP), and prefixed with the s2k specifier.
  1286.   This is then encoded in hexadecimal, prefixed by the indicator sequence
  1287.   "16:".  Thus, for example, the password 'foo' could encode to:
  1288.      16:660537E3E1CD49996044A3BF558097A981F539FEA2F9DA662B4626C1C2
  1289.         ++++++++++++++++**^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1290.            salt                       hashed value
  1291.                        indicator
  1292.   You can generate the salt of a password by calling
  1293.            'tor --hash-password <password>'
  1294.   or by using the example code in the Python and Java controller libraries.
  1295.   To authenticate under this scheme, the controller sends Tor the original
  1296.   secret that was used to generate the password.
  1297.  
  1298. 5.2. Don't let the buffer get too big.
  1299.  
  1300.   If you ask for lots of events, and 16MB of them queue up on the buffer,
  1301.   the Tor process will close the socket.
  1302.  
  1303. 5.3. Backward compatibility with v0 control protocol.
  1304.  
  1305.   For backward compatibility with the "version 0" control protocol, Tor checks
  1306.   whether the third octet the first command is zero.  If it is, Tor
  1307.   assumes that version 0 is in use.  This feature is deprecated, and will be
  1308.   removed in the 0.1.3.x Tor development series.
  1309.  
  1310.   In order to detect which version of the protocol is supported controllers
  1311.   should send the sequence [00 00 0D 0A].  This is a valid and unrecognized
  1312.   command in both protocol versions, and implementations can detect which
  1313.   error they have received.
  1314.  
  1315.